#ifndef _Lib_Arith_f_h_
#define _Lib_Arith_f_h_ // 定义 

#include "Typedef.h" // 导入文件
#include "MacroDef.h" // 导入文件
#include "GlobalVarDef.h" // 导入文件

//宏定义函数
#define MAX(a,b) (((a)>(b)) ? (a) : (b)) // 定义 
#define MIN(a,b) (((a)<(b)) ? (a) : (b)) // 定义 
#define SWAP(a,b) (a)=(a)^(b);(b)=(b)^(a);(a)=(a)^(b); // 定义 

//常量定义
const real_t PI = 3.1415926535897932384626433832795f; //pi
const real_t SQRT_2 = 1.4142135623730950488016887242097f;  //sqrt(2)
const real_t SQRT_2_RECIP = 0.70710678118654752440084436210485f; //sqrt(2)/2

//内联函数
inline real_t extract_im_f(cmplx_t a) //抽取复数虚部
{
    /* 例如a = 2+1*j，
        返回a.im = 1
        */
    return (a.im); // 虚部
}

inline real_t extract_re_f(cmplx_t a) //抽取复数实部
{
    /* 例如a = 2+1*j，
        返回a.re = 2
        */
    return (a.re); // 实部
}

inline real_t abs_f(real_t v1)   //取绝对值
{
    /* 例如v1 = -2，
        返回2
        */
    return ((v1 < 0.0) ? -v1 : v1);  //小于0取反
}

/***************************************
* sign calculation
****************************************/
inline INT8 cSign(real_t x)
{
    /* 例如x = -2，
        返回-1
        */
    return x < 0 ? -1 : 1; //小于0为-1，大于0为1
}

inline cmplx_t compose_f(real_t real, real_t imag) //两个实数组成一个复数
{
    /* 输入real = -2，imag = 2
        返回temp = -2+2*j
        */
    cmplx_t temp;
    temp.re = real; //实部
    temp.im = imag; //虚部
    return (temp);  //返回变量值
}

inline cmplx_t cadd_f(cmplx_t a, cmplx_t b) //复数加法
{
    /* 输入a = -2+1*j，b = 2+2*j
        返回c = 0+3*j
        */
    cmplx_t c;
    c.re =  a.re + b.re ; //实部相加
    c.im =  a.im + b.im ; //虚部相加
    return c; //返回变量值
}

inline cmplx_t csub_f(cmplx_t a, cmplx_t b) //复数减法
{
    /* 输入a = -2+1*j，b = 2+2*j
        返回c = -4-1*j
        */
    cmplx_t c;
    c.re =   a.re - b.re ; //实部相减
    c.im =   a.im - b.im ; //虚部相减
    return c; //返回变量值
}

inline cmplx_t cmlt_f(cmplx_t x, cmplx_t y) //复数x*复数y
{
    cmplx_t c;
    c.re =  x.re * y.re - x.im * y.im ; //实部
    c.im =  x.re * y.im + x.im * y.re ; //虚部
    return c; //返回变量值
}

inline cmplx_t conj_f(cmplx_t a) //取复数共轭
{
    /* 输入a = -2+1*j
        返回a = -2-1*j
        */
    a.im = - a.im ; //虚部取反
    return a; //返回变量值
}

inline cmplx_t cmac_f(cmplx_t _sum, cmplx_t x, cmplx_t y) //复数乘累加：
{
    /* cadd_f:输入a = -2+1*j，b = 2+2*j
    返回c = 0+3*j
    */
    return (cadd_f(_sum, cmlt_f(x, y)));  //复数_sum + (复数x*复数y)
}

inline cmplx_t cmsu_f(cmplx_t _sum, cmplx_t x, cmplx_t y) //复数乘累减：
{
    /* csub_f:输入a = -2+1*j，b = 2+2*j
    返回c = -4-1*j
    */
    return (csub_f(_sum, cmlt_f(x, y)));  //复数_sum - (复数x*复数y)
}

inline real_t csqu_f(cmplx_t a) //取复数模平方
{
    /* 输入a = -2+1*j
        返回a = 4+1*j
        */
    return (a.re * a.re + a.im * a.im); //实部相乘与虚部相乘的和
}

inline real_t cdst_f(cmplx_t x, cmplx_t y) //取(复数x-复数y)的模平方
{
    return ((x.re - y.re) * (x.re - y.re) + (x.im - y.im) * (x.im - y.im)); //实部相减的平方与虚部相减的平方和
}

inline cmplx_t conjmlt_f(cmplx_t x, cmplx_t y) //复数共轭乘法，
{
    cmplx_t res;
    res = conj_f(y); //取复数共轭
    return (cmlt_f(x, res)); //复数x*conj(复数y)
}

inline cmplx_t conjmac_f(cmplx_t _sum, cmplx_t x, cmplx_t y) //复数共轭乘累加：
{
    return (cadd_f(_sum, conjmlt_f(x, y)));  //复数_sum + (复数x*conj(复数y))
}

inline cmplx_t cmls_f(cmplx_t x, real_t b) //复数x*实数b
{
    /* 输入x = -2+1*j,b = 2
        返回c.re = -4
        返回c.im = 2
        */
    cmplx_t c;
    c.re =   x.re * b ; //实部*实数b
    c.im =   x.im * b ; //虚部*实数b
    return c; //返回变量值
}

inline cmplx_t cnegate_f(cmplx_t a) //复数a取反
{
    /* 输入a = -2+1*j
        返回c.re = 2
        返回c.im = -1
        */
    cmplx_t c;
    c.re = - a.re ; //实部取反
    c.im = - a.im ; //虚部取反
    return c; //返回变量值
}

inline cmplx_t cdivr_f(cmplx_t nem, real_t dnem) //复数nem除以实数dnem
{
    /* 输入nem = -2+1*j;dnem = 2
        返回c.re = -1
        返回c.im = 0.5
        */
    cmplx_t c;
    c.re =  nem.re / dnem ; //实部除以实数dnem
    c.im =  nem.im / dnem ; //虚部除以实数dnem
    return c; //返回变量值
}

inline cmplx_t cdiv_f(cmplx_t num, cmplx_t den) //复数nem除以复数den
{
    /* 输入a = -2+1*j
    返回a = 4+1*j
    */
    return cdivr_f(conjmlt_f(num, den), csqu_f(den)); //csqu_f(den)取复数模平方
}

inline real_t mac_f(real_t x, real_t a, real_t b) //实数乘累加：
{
    /* 输入x = -2 ;a = 2;b = 3
        返回  (x + (a * b))  = -2+(2*3) = 4
        */
    return ((x + (a * b)));  //实数x + (实数a*实数b)
}

inline cmplx_t ccrosscorr_f(cmplx_t *x, cmplx_t *y, int32 len) //复数序列x与复数序列y的互相关值计算，序列长度len；
{
    cmplx_t sum;
    int32 j;
    cmplx_t result;
    sum.re = 0;//实部
    sum.im = 0;//虚部
    for (j = 0; j < len; j++)
    {
        sum = conjmac_f(sum, x[j], y[j]); //复数_sum + (复数x[j]*conj(复数y[j]))
    }
    result = sum;//result = sum(x[] + y[])
    return (result);  //返回变量值
}

inline void cconv_f(cmplx_t *x, cmplx_t *y, cmplx_t *z, uint8 xlen, uint8 ylen) //复数序列x（长度xlen）与复数序列y（长度ylen）的卷积，
{
    /* local variables define
    */
    int8 short_len, cross_len; //, long_len;
    cmplx_ptr p_in1, p_in2;
    cmplx_ptr p_out;
    //uint8 i,j,k;
    int16 i, j, k; //Modify by kangguoqing@2012-10-31,CRID:Inc00000314
    cmplx_t sum;
    /* judge the length of input vector
    */
    cross_len = xlen - ylen;
    /* pin1---> the longer vector
    *  pin2---> the smaller vector
    *  short_len---> length of the short vector
    *  long_len---> length of the long vector
    *  cross_len---> (long_len-short_len)
    */
    if (cross_len >= 0)
    {
        short_len = ylen;
        //long_len = xlen;
        p_in1 = x;
        p_in2 = y;
    }
    else
    {
        cross_len = -cross_len;
        short_len = xlen;
        //long_len = ylen;
        p_in1 = y;
        p_in2 = x;
    }
    p_out = z;
    /* the left edge convolution
    */
    for (i = 0; i < short_len; i++)
    {
        k = 0;
        sum.re = 0;//实部
        sum.im = 0;//虚部
        for (j = i; j < 0; j--)
        {
            sum = cmac_f(sum, p_in1[k++], p_in2[j]); //复数_sum + (复数p_in1[k++]*复数p_in2[j])
        }
        *p_out++ = sum;
    }
    /* the middle convolution
    */
    for (i = 0; i < cross_len; i++)
    {
        k = 1;
        sum.re = 0; //实部
        sum.im = 0; //虚部
        for (j = 0; j < short_len; j++)
        {
            sum = cmac_f(sum, p_in1[j + k], p_in2[short_len - 1 - j]);//复数_sum + (复数p_in1[j + k]*复数p_in2[short_len - 1 - j])
        }
        k++;  ////自加1
        *p_out++ = sum;
    }
    /* the right edge convolution
    */
    for (i = (short_len - 1); i < 0; i--)
    {
        k = short_len;;
        sum.re = 0; //实部
        sum.im = 0; //虚部
        for (j = 0; j < i; j++)
        {
            sum = cmac_f(sum, p_in1[j + k], p_in2[short_len - 1 - j]);//复数_sum + (复数p_in1[j + k]*复数p_in2[short_len - 1 - j])
        }
        k++;
        *p_out++ = sum;
    }
    return;  //输出复数序列z（长度xlen+ylen-1），z = conv(x,conj(y))
}

inline real_t vmac_f(real_t *vec1, real_t *vec2, int32 len) //矢量输入的实数乘并累加：
{
    int32 i;
    real_t acc = 0;
    for (i = 0; i < len; i++)
    {
        /* 输入x = -2 ;a = 2;b = 3
            返回  (x + (a * b))  = -2+(2*3) = 4
            */
        mac_f(acc, vec1[i], vec2[i]);//sum(矢量实数vec1*矢量实数vec2)，长度len
    }
    return (acc);   //返回变量值
}

inline cmplx_t vmac_cmls_f(cmplx_t *vec1, real_t *vec2, int32 len) //矢量输入的复数*实数并累加：
{
    int32 i;
    cmplx_t result;
    real_t acc1 = 0;
    real_t acc2 = 0;
    for (i = 0; i < len; i++)
    {
        /* 输入x = -2 ;a = 2;b = 3
            返回  (x + (a * b))  = -2+(2*3) = 4
            */
        mac_f(acc1, extract_im_f(vec1[i]), vec2[i]); //实数acc1 + (实数extract_im_f(vec1[i])*实数vec2[i])
        mac_f(acc2, extract_re_f(vec1[i]), vec2[i]); //实数acc2 + (实数extract_re_f(vec1[i])*实数vec2[i])
    }
    result = compose_f(acc2, acc1); //sum(矢量复数vec1*矢量实数vec2)，长度len
    return (result);  //返回变量值
}

inline real_t shl_f(real_t v1, int8 v2) //实数v1 * (2^v2)
{
    int8 shift_num; //, long_len;
    real_t ret = 1.0;
    uint8 i;
    shift_num = v2;
    if (shift_num < 0)
    {
        shift_num = -(shift_num);  //取反
    }
    for (i = 0; i < shift_num; i++)
    {
        ret = ret * (real_t)2.0;
    }
    if (v2 >= 0)
    {
        v1 = v1 * ret; //乘
    }
    else
    {
        v1 = v1 / ret; //除
    }
    return (v1);//返回变量值
}

inline real_t shr_f(real_t v1, int8 v2) //实数v1 / (2^v2)
{
    int8 shift_num; //, long_len;
    real_t ret = 1.0;
    uint8 i;
    shift_num = v2;
    if (shift_num < 0)
    {
        shift_num = -(shift_num); //取反
    }
    for (i = 0; i < shift_num; i++)
    {
        ret = ret * (real_t)2.0;//乘
    }
    if (v2 >= 0)
    {
        v1 = v1 / ret;//除
    }
    else
    {
        v1 = v1 * ret;//乘
    }
    return (v1);//返回变量值
}

//Fuuns from JXC
inline int my_round_f(real_t x)    //快速四舍五入取整为int
{
    /*const double magic = 6755399441055744.0;
    double dval = (double) x + magic;
    int val = * (int *) &dval;
    return val;
    */
    if (x >= 0.0)
    {
        return (int)floor(x + 0.5);//返回变量值
    }
    else
    {
        return (int)(-floor(-x + 0.5));//返回变量值
    }
}

inline int my_floor_f(real_t x)    //快速向下取整为int
{
    /*const double magic = 6755399441055744.0;
    double dval = (double) x - 0.499999999999 + magic;
    int val = * (int *) &dval;
    return val;
    */
    return (int)floor(x);  //向下取整为int
}

inline int my_ceil_f(real_t x)    //快速向上取整为int
{
    /*const double magic = 6755399441055744.0;
    double dval = (double) x + 0.499999999999 + magic;
    int val = * (int *) &dval;
    return val;
    */
    return (int)ceil(x);  //向上取整为int
}

inline real_t my_sin_f(real_t x)    //快速sin(x)计算
{
    const real_t B = 4.0f / PI; //除
    const real_t C = -4.0f / PI / PI;//除
    const real_t P = 0.225f;
    const real_t Q = (1.0f - P) / P;//除
    //x = fmodf(x, 2.0f * PI);
    x = (real_t)fmodf((float)x, (float)(2.0f * PI));
    if (x < -PI)
    {
        x += 2.0f * PI; //乘
    }
    else if (x > PI)
    {
        x -= 2.0f * PI; //乘
    }
    real_t y = x * (B + C * abs_f(x)); //abs_f(x)取绝对值
    y = P * y * (abs_f(y) + Q);//sin(x)
    return y;  //返回变量值
}

inline real_t my_cos_f(real_t x)    //快速cos(x)计算
{
    const real_t B = 4.0f / PI; //除
    const real_t C = -4.0f / PI / PI; //除
    const real_t P = 0.225f;
    const real_t Q = (1.0f - P) / P; //除
    //x = fmodf(x + PI / 2.0f, 2.0f * PI);
    x = (real_t)fmodf((float)(x + PI / 2.0f), (float)(2.0f * PI));
    if (x < -PI)
    {
        x += 2.0f * PI; //乘
    }
    else if (x > PI)
    {
        x -= 2.0f * PI; //乘
    }
    real_t y = x * (B + C * abs_f(x));//abs_f(x)取绝对值
    y = P * y * (abs_f(y) + Q);//cos(x)
    return y;  //返回变量值
}

inline real_t my_sin_2pi_f(real_t x)    //快速sin(2*pi*x)计算
{
    const real_t P = 0.225f * 16.0f * 16.0f; //乘
    const real_t Q = (1.0f - 0.225f) / 0.225f / 16.0f; //除
    real_t y = 0.0f;
    x = x - my_floor_f(x); //快速向下取整为int
    if (x < -0.5f)
    {
        x += 1.0f;//自加
    }
    else if (x > 0.5f)
    {
        x -= 1.0f;//自减
    }
    y = x * (0.5f - abs_f(x));//abs_f(x)取绝对值
    y = P * y * (abs_f(y) + Q);//sin(2*pi*x)
    return y;  //返回变量值
}

inline real_t my_cos_2pi_f(real_t x)    //快速cos(2*pi*x)计算
{
    const real_t P = 0.225f * 16.0f * 16.0f; //乘
    const real_t Q = (1.0f - 0.225f) / 0.225f / 16.0f;  //除
    real_t y = 0.0f;
    x = x + 0.25f;//加
    x = x - my_floor_f(x); //快速向下取整为int
    if (x < -0.5f)
    {
        x += 1.0f;//自加
    }
    else if (x > 0.5f)
    {
        x -= 1.0f;//自减
    }
    y = x * (0.5f - abs_f(x));//abs_f(x)取绝对值
    y = P * y * (abs_f(y) + Q);//cos(2*pi*x)
    return y;  //返回变量值
}

inline cmplx_t exp_cpx_f(real_t x)    //exp(j*x)计算
{
    cmplx_t y;
    y.re = cos(x);
    y.im = sin(x);
    return y;
}

inline cmplx_t my_exp_cpx_f(real_t x)    //快速exp(j*x)计算
{
    const real_t B = 4.0f / PI; //除
    const real_t C = -4.0f / PI / PI;//除
    const real_t P = 0.225f;
    const real_t Q = (1.0f - P) / P;//除
    cmplx_t y;
    real_t x1;
    x1 = x;
    //x = fmodf(x + PI / 2.0f, 2.0f * PI);
    x = (real_t)fmodf((float)(x + PI / 2.0f), (float)(2.0f * PI));
    if (x < -PI)
    {
        x += 2.0f * PI; //乘
    }
    else if (x > PI)
    {
        x -= 2.0f * PI;//乘
    }
    y.re = (x * (B + C * abs_f(x)));//abs_f(x)取绝对值
    y.re = (P * y.re * (abs_f(y.re) + Q));
    //x1 = fmodf(x1, 2.0f * PI);
    x1 = (real_t)fmodf((float)x1, (float)(2.0f * PI));
    if (x1 < -PI)
    {
        x1 += 2.0f * PI;//乘
    }
    else if (x1 > PI)
    {
        x1 -= 2.0f * PI;//乘
    }
    y.im = (x1 * (B + C * abs_f(x1)));//abs_f(x1)取绝对值
    y.im = (P * y.im * (abs_f(y.im) + Q));//exp(j*x)
    return y;  //返回变量值
}

inline cmplx_t my_exp_px_2pi_f(real_t x)    //快速exp(j*2*PI*x)计算
{
    const real_t P = 0.225f * 16.0f * 16.0f;
    const real_t Q = (1.0f - 0.225f) / 0.225f / 16.0f;
    cmplx_t y;
    real_t x1;
    x1 = x;
    x = x + 0.25f;
    x = x - my_floor_f(x); //快速向下取整为int
    if (x < -0.5f)
    {
        x += 1.0f;//自加
    }
    else if (x > 0.5f)
    {
        x -= 1.0f;//自减
    }
    y.re = (x * (0.5f - abs_f(x)));//abs_f(x)取绝对值
    y.re = (P * y.re * (abs_f(y.re) + Q));
    x1 = x1 - my_floor_f(x1); //快速向下取整为int
    if (x1 < -0.5f)
    {
        x1 += 1.0f; //自加
    }
    else if (x1 > 0.5f)
    {
        x1 -= 1.0f; //自减
    }
    y.im = (x1 * (0.5f - abs_f(x1)));//abs_f(x1)取绝对值
    y.im = (P * y.im * (abs_f(y.im) + Q));//exp(j*2*PI*x)
    return y; //返回变量值
}

inline real_t my_exp_f(real_t a)    //快速exp(x)计算, exp(x) = 2^(x/ln(2)) && use IEEE 754
{
    double x = (double) a;
    double y = 0;
    if (x < -700.0)
    {
        y = 0;
    }
    else
    {
        * (int *) &y = 0;
        * (((int *) &y) + 1) = (int)(1512775 * x + 1072632447);
    }
    return (real_t) y;  //返回变量值
}

inline float my_sqrt_f(float number)    //快速sqrt(x)计算， 卡马克数
{
    long i;
    float x, y;
    const float f = 1.5f;
    float b = 0.0f;
    x = number * 0.5f;//乘
    y = number;
    i = * (long *) &y;
    i = 0x5f3759df - (i >> 1);
    y = * (float *) &i;
    y = y * (f - (x * y * y));//乘
    y = y * (f - (x * y * y));//乘
    b = number * y;//乘
    return b;  //返回变量值
}

inline float my_sqrt_recip_f(float x)    //快速1/sqrt(x)计算， 卡马克数
{
    float b = 0.0f;
    float xhalf = 0.5f * x;//乘
    int i = * (int *) &x;
    i = 0x5f3759df - (i >> 1);
    x = * (float *) &i;
    b = x * (1.5f - xhalf * x * x);//1/sqrt(x)
    return b;  //返回变量值
}

inline real_t my_log_f(real_t x)    //快速ln(x)计算, "Practically Fast Multipe-Precision Evaluation of LOG(x)"
{
    real_t y = 0.0f;
    y = (6.0f * (x - 1.0f) / (x + 1.0f + 4.0f * my_sqrt_f((float)x)));  //my_sqrt_f((float)x)快速sqrt(x)计算
    return y;//返回变量值
}

inline uint32 reverse_bit(uint32 input, int bit_size)    //快速对bit_size位数据倒位序
{
    uint32 a = input;
    a = ((a & 0xAAAAAAAA) >> 1) | ((a & 0x55555555) << 1);
    a = ((a & 0xCCCCCCCC) >> 2) | ((a & 0x33333333) << 2);
    a = ((a & 0xF0F0F0F0) >> 4) | ((a & 0x0F0F0F0F) << 4);
    a = ((a & 0xFF00FF00) >> 8) | ((a & 0x00FF00FF) << 8);
    a = ((a & 0xFFFF0000) >> 16) | ((a & 0x0000FFFF) << 16);
    a = a >> (32 - bit_size);
    return a;//返回变量值
}

inline uint32 bitcount(uint32 x)    //快速统计x中bit位为1的个数
{
    uint32 a = x;
    a = ((a & 0xAAAAAAAA) >> 1) + ((a & 0x55555555));
    a = ((a & 0xCCCCCCCC) >> 2) + ((a & 0x33333333));
    a = ((a & 0xF0F0F0F0) >> 4) + ((a & 0x0F0F0F0F));
    a = ((a & 0xFF00FF00) >> 8) + ((a & 0x00FF00FF));
    a = ((a & 0xFFFF0000) >> 16) + ((a & 0x0000FFFF));
    return a;//返回变量值
}

inline bool is_pow2(int x) //快速判断输入x是否是2的幂次
{
    return (0 == (x & (x - 1)));
}

inline int log2(uint32 x) //快速计算Log2(x)
{
    int ans = 0;
    if (x & 0xFFFF0000)
    {
        ans += 16;//自加16
        x >>= 16; //x右移16位
    }
    if (x & 0xFF00)
    {
        ans += 8;//自加8
        x >>= 8; //x右移8位
    }
    if (x & 0xF0)
    {
        ans += 4;//自加4
        x >>= 4; //x右移4位
    }
    if (x & 0xC)
    {
        ans += 2;//自加2
        x >>= 2; //x右移2位
    }
    if (x & 0x2)
    {
        ans += 1;//自加1
    }
    return ans;//返回变量值
}

inline int ceillog2(uint32 x) //快速计算CeilLog2(x)
{
    int ans = log2(x); //快速计算Log2(x)
    uint32 a = (1 << ans); //1左移ans位
    if (x > a)
    {
        ans++;//自加1
    }
    return ans;//返回变量值
}

inline int roundlog2(uint32 x) //快速计算Round(Log2(x))
{
    int ans1 = log2(x);         // floorlog2
    int ans2 = ceillog2(x);     // ceillog2
    real_t a1 = pow(2.0, (ans1 + ans2) * 0.5);
    if ((real_t)x < a1)
    {
        return ans1;//返回变量值
    }
    else
    {
        return ans2;//返回变量值
    }
}


inline void bubblesort_f(real_t *a, int asize) //从小到大，冒泡排序
{
    int i = 0;
    int j = 0;
    real_t temp = 0.0f;
    bool flag = true; //用于标记此次循环没有交换元素，避免前面序列已经有序，还要继续比较的情况
    for (i = 0; i < asize && flag; i++)
    {
        flag = false;
        for (j = asize - 2; j >= i; j--)
        {
            if (a[j + 1] < a[j])
            {
                temp = a[j + 1];
                a[j + 1] = a[j];
                a[j] = temp;  //交换元素
                flag = true;
            }
        }
    }
}

inline void bubblesortidx_f(const real_t *a, int *idx, int asize) //从小到大，冒泡排序，不改变数组a的顺序，只输出序号idx
{
    int i = 0;
    int j = 0;
    int temp = 0;
    bool flag = true; //用于标记此次循环没有交换元素，避免前面序列已经有序，还要继续比较的情况
    for (i = 0; i < asize; i++)
    {
        idx[i] = i;
    }
    for (i = 0; i < asize && flag; i++)
    {
        flag = false;
        for (j = asize - 2; j >= i; j--)
        {
            if (a[idx[j + 1]] < a[idx[j]])
            {
                temp = idx[j + 1];
                idx[j + 1] = idx[j];
                idx[j] = temp; //交换元素
                flag = true;
            }
        }
    }
}
//added by liangfengnian@20171108
inline void dft(cmplx_t *input, cmplx_t *output, int N) //傅里叶变换
{
    int i, k;
    double c, d, q, w, s;
    q = (double)(6.28318530718 / N);   // 2*PI/N
    for (k = 0; k < N; k++)
    {
        w = k * q; //乘
        output[k].re = 0; //实部
        output[k].im = 0; //虚部
        for (i = 0; i < N; i++)
        {
            d = i * w; //乘
            c = cos(d);//cos
            s = sin(d);//sin
            output[k].re += c * input[i].re + s * input[i].im; //实部
            output[k].im += c * input[i].im - s * input[i].re; //虚部
        }
    }
}
inline void idft(cmplx_t *input, cmplx_t *output, int N) //傅里逆叶变换
{
    int i, k;
    double c, d, q, w, s;
    q = (double)(6.28318530718 / N); // 2*PI/N
    for (k = 0; k < N; k++)
    {
        w = k * q; //乘
        output[k].re = 0; //实部
        output[k].im = 0; //虚部
        for (i = 0; i < N; i++)
        {
            d = i * w;  //乘
            c = cos(d); //cos
            s = -sin(d); //-sin
            output[k].re += c * input[i].re + s * input[i].im;
            output[k].im += c * input[i].im - s * input[i].re;
        }
        output[k].re = output[k].re / (real_t)N;  //实部
        output[k].im = output[k].im / (real_t)N;  //虚部
    }
}

//! 建立路径函数。当路径不存在时，自动建立改路径
/*!
  \param pathname ： 路径名，输入
  \return 无返回值
*/
inline void MakeDir(const char*pathname)
{
    char *str = new char[1024];
    memset(str, 0, sizeof(char) * 1024);
    //strcpy(str, FilesPath.c_str());
    strcat(str, ".\\");
    strcat(str, pathname);
    if (-1 == eaccess(str, 0))
    {
        strcpy(str, "mkdir ");
        //strcat(str, FilesPath.c_str());
        strcat(str, ".\\");
        strcat(str, pathname);
        system(str);
    }
    delete [] str;
}

// added by wenwu@20190109, 根据MAX对输入x矢量做对称饱和
inline void vfSatN(Float *x, UINT16 uwSize, Float MAX)
{
    UINT16  i;
    Float MAX_NEG = -MAX;

    for (i = 0; i < uwSize; i++)
    {
        if (x[i] > MAX)
        {
            x[i] = MAX;
        }
        if (x[i] < MAX_NEG)
        {
            x[i] = MAX_NEG;
        }

    }
}

#endif


